Support CJS file extensions#12021
Conversation
|
👍 would be great to see this merged, quite a few libraries use .cjs (e.g. |
|
@jenseng Second that! This is also affecting the very popular file uploader package |
|
This PR successfully fixes the issue for my project. |
|
Would love if this gets merged in as it solves issues with a lot of libs |
|
Would be great to have this merged in. In the meantime, it's possible to continue using // config-overrides.js
module.exports = {
webpack: function (config, env) {
config.module.rules = config.module.rules.map(rule => {
if (rule.oneOf instanceof Array) {
rule.oneOf[rule.oneOf.length - 1].exclude = [/\.(js|mjs|jsx|cjs|ts|tsx)$/, /\.html$/, /\.json$/];
}
return rule;
});
return config;
},
} |
|
Guys, any update on this ? |
|
This solved our issue in solana-labs/oyster#538 - it would be great to have this merged! 🙏 |
|
Any update? This is a blocker! |
|
Looking forward to someone finally fixing this. |
|
We need this as well and it's really important for our team, @UPPY doesn't work without a |
|
Hey @nyatskiv Install these packagesUpdate your build and start scriptsCreate a //@ts-ignore
const {
override,
addWebpackModuleRule,
setWebpackTarget,
} = require("customize-cra");
module.exports = override(
addWebpackModuleRule({
test: /\.(cjs)$/,
exclude: /@babel(?:\/|\\{1,2})runtime/,
loader: require.resolve("babel-loader"),
options: {
babelrc: false,
configFile: false,
compact: false,
presets: [
[
require.resolve("babel-preset-react-app/dependencies"),
{ helpers: true },
],
],
cacheDirectory: true,
cacheCompression: false,
sourceMaps: true,
inputSourceMap: true,
},
})
); |
|
+1 Hoping this will be reviewed and merged. This fixes an issue I'm having and I believe this would fix #12155. |
* use spl-governance serializers * fix demo app setting GENERATE_SOURCEMAP=false due to react/create-react-app#11752 also using react-app-rewired due to react/create-react-app#12021 and solana-labs/oyster#538
You are my new favorite internet stranger @nyan-left! I've spent all afternoon fighting with this trying to figure out why my dependency importing axios wasn't working! Thanks a lot, hopefully this can get merged in to fix it properly ASAP. |
|
I also would love for this to be reviewed and merged. 🙏 |
Same here, importing axios@1.3.3 as I could work around this by adding CRACO to my project, with the configuration suggested here: #11889 (comment). Is there any estimated ETA for merging this PR, so we can just use latest react-scripts and axios versions out of the box? |
|
This PR has been kicking around for a year, and it clearly solves a known issue. What's blocking the progress here? 😖 It, and several other PRs doing the same thing, seem like they would effectively solve #12700. |
|
Ran into this issue today, I'm glad I was able to eventually find this PR and learn about the root cause + workarounds. But like the previous commenter, I'm also wondering what is blocking the PR for so long. This seems like a good solution for an issue that has been reported multiple times by now. |
|
I think we need to give up on create react app, it looks like they are not supporting it anymore with the new docs anyway. If you have a look at my comment from 9 months ago there is a way to use rewire to solve the issue |
@nigelheap, can you expand on what you mean? Or link to where in the docs it says that they are not supporting (and what they're note supporting)? |
@laustdeleuran The new react docs don't mention using create react app. Specific part about not using a framework https://react.dev/learn/start-a-new-react-project#can-i-use-react-without-a-framework |
|
Hello from 2023, burned a few hours on this frustrating issue! Any chance of getting this merged? |
|
I'm also having this issue. |
|
@zpao sorry for the direct hit. But can you help merging this? Thank you |
|
It is sad that this has not been sorted after 1 year of collective frustration - what is up? |
|
I'm still hopping this gets merge :/ |
Summary: Known issue with create-react-app. As more dependencies use these files, will need this support. Main issue now is that the latest chronik-client won't work, since it uses the latest version of axios, which uses cjs files. Cashtab will work with the latest version of chronik-client with this webpack config. I can wait and add them together so there is a test plan, but imo it makes sense to keep this as an isolated change. This is more or less a backport of (still unmerged) react/create-react-app#12021 Cashtab was initially a create-react-app app, but has been ejected and customized to support crypto dependencies. Test Plan: `npm test` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Subscribers: Fabien Differential Revision: https://reviews.bitcoinabc.org/D15077
|
This issue is still breaking otherwise correctly written packages used within CRA projects (e.g. 101arrowz/fflate#193). |
|
My take here is that CRA is now abandonware and we should either eject, or migrate to other providers like vite. |

Currently CRA treats
.cjsfiles asasset/resourcefiles rather than javascript files. See https://nodejs.org/api/packages.html#determining-module-system for explanation of how the.cjsfile extension is treated by NodeJS.I wasn't able to add tests to this PR because all of the tests failed epicly when I ran them locally, after following the instructions in CONTRIBUTING.md and swapping between Node 14, 16, and 17. I manually tested this change on a local create-react-app project to verify that CJS files are now processed as javascript. I expect the lack of tests will make this PR not mergeable, so any guidance on how to fix the many many errors that occur while running
npx jest test/ --watchAllis appreciated.